package cn.gameback.supervisionservices.mapper;

import cn.gameback.supervisionservices.entity.Role;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.Collection;
import java.util.List;
import java.util.Map;

@Mapper
public interface RoleMapper extends BaseMapper<Role> {
    // ????????
    @Select("SELECT description FROM role WHERE id = #{id}")
    String getDescriptionByRoleId(@Param("id") Integer roleId);

    @Select({
            "<script>",
            "SELECT id AS roleId, description",
            "FROM role",
            "WHERE id IN",
            "<foreach collection='roleIds' item='item' open='(' separator=',' close=')'>",
            "   #{item}",
            "</foreach>",
            "</script>"
    })
    @ResultType(Map.class)
    @MapKey("roleId")
    Map<Integer, String> getDescriptionsByRoleIds(@Param("roleIds") Collection<Integer> roleIds);

    // 通过 description 查询角色id
    @Select("SELECT id FROM role WHERE description = #{description}")
    Integer getRoleIdByDescription(@Param("description") String description);
}
